package d3_annotation;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;

public class AnnotationDemo03 {
    //目标: 解析注解
    @Test
    public void parseClass() {
        //1、第一步得到类对象
        Class c = Demo.class;

        //2、判断上面是否存在MyBook4注解
        //为什么要填类型-->因为上面可能有其他注解,要进行区分
        if (c.isAnnotationPresent(MyBook4.class)) {//存在就会返回false
            //3、拿到这个注解
            MyBook4 myBook4 = (MyBook4) c.getDeclaredAnnotation(MyBook4.class);
            System.out.println(myBook4.value());
            System.out.println(myBook4.aaa());//以方法的形式获取
//            System.out.println(myBook4.bbb());
            System.out.println(Arrays.toString(myBook4.bbb()));
        }
    }
    @Test
    public void parseMethod() throws Exception {
        //1、第一步得到类对象
        Class c = Demo.class;
        //1.2获取方法对象
        Method test = c.getDeclaredMethod("test");

        //2、判断上面是否存在MyBook4注解
        //为什么要填类型-->因为上面可能有其他注解,要进行区分
        if (test.isAnnotationPresent(MyBook4.class)) {//存在就会返回false
            //3、拿到这个注解
            MyBook4 myBook4 = (MyBook4) test.getDeclaredAnnotation(MyBook4.class);
            System.out.println(myBook4.value());
            System.out.println(myBook4.aaa());//以方法的形式获取
//            System.out.println(myBook4.bbb());
            System.out.println(Arrays.toString(myBook4.bbb()));
        }
    }
}


@MyBook4(value = "陈平安", aaa = 99.7, bbb = {"宁姚", "姚姚"})
@MyBook3("陈")
class Demo {
    @MyBook4(value = "宁姚", aaa = 99.6, bbb = {"陈平安", "安安"})
    public void test() {

    }

}